﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using UnityEngine;

// Token: 0x02000362 RID: 866
internal class XmlResourceSettingReader
{
	// Token: 0x06001653 RID: 5715 RVA: 0x000917C0 File Offset: 0x0008F9C0
	public XmlResourceSettingReader(bool loadSettings = true)
	{
		if (loadSettings)
		{
			this.LoadFromFile();
		}
		else
		{
			this.InitLists();
		}
	}

	// Token: 0x1700037B RID: 891
	// (get) Token: 0x06001655 RID: 5717 RVA: 0x0009185B File Offset: 0x0008FA5B
	// (set) Token: 0x06001654 RID: 5716 RVA: 0x00091852 File Offset: 0x0008FA52
	public List<string> GiantessPaths { get; private set; }

	// Token: 0x1700037C RID: 892
	// (get) Token: 0x06001657 RID: 5719 RVA: 0x0009186C File Offset: 0x0008FA6C
	// (set) Token: 0x06001656 RID: 5718 RVA: 0x00091863 File Offset: 0x0008FA63
	public List<string> PlayerModelPaths { get; private set; }

	// Token: 0x1700037D RID: 893
	// (get) Token: 0x06001659 RID: 5721 RVA: 0x0009187D File Offset: 0x0008FA7D
	// (set) Token: 0x06001658 RID: 5720 RVA: 0x00091874 File Offset: 0x0008FA74
	public List<string> MaleNpcPaths { get; private set; }

	// Token: 0x1700037E RID: 894
	// (get) Token: 0x0600165B RID: 5723 RVA: 0x0009188E File Offset: 0x0008FA8E
	// (set) Token: 0x0600165A RID: 5722 RVA: 0x00091885 File Offset: 0x0008FA85
	public List<string> FemaleNpcPaths { get; private set; }

	// Token: 0x1700037F RID: 895
	// (get) Token: 0x0600165D RID: 5725 RVA: 0x0009189F File Offset: 0x0008FA9F
	// (set) Token: 0x0600165C RID: 5724 RVA: 0x00091896 File Offset: 0x0008FA96
	public List<string> ObjectPaths { get; private set; }

	// Token: 0x17000380 RID: 896
	// (get) Token: 0x0600165F RID: 5727 RVA: 0x000918B0 File Offset: 0x0008FAB0
	// (set) Token: 0x0600165E RID: 5726 RVA: 0x000918A7 File Offset: 0x0008FAA7
	public List<string> SoundPaths { get; private set; }

	// Token: 0x17000381 RID: 897
	// (get) Token: 0x06001661 RID: 5729 RVA: 0x000918C1 File Offset: 0x0008FAC1
	// (set) Token: 0x06001660 RID: 5728 RVA: 0x000918B8 File Offset: 0x0008FAB8
	public List<string> ScenePaths { get; private set; }

	// Token: 0x17000382 RID: 898
	// (get) Token: 0x06001663 RID: 5731 RVA: 0x000918D2 File Offset: 0x0008FAD2
	// (set) Token: 0x06001662 RID: 5730 RVA: 0x000918C9 File Offset: 0x0008FAC9
	public List<string> LuaPaths { get; private set; }

	// Token: 0x17000383 RID: 899
	// (get) Token: 0x06001665 RID: 5733 RVA: 0x000918E3 File Offset: 0x0008FAE3
	// (set) Token: 0x06001664 RID: 5732 RVA: 0x000918DA File Offset: 0x0008FADA
	public string ScreenShotPath { get; private set; }

	// Token: 0x17000384 RID: 900
	// (get) Token: 0x06001667 RID: 5735 RVA: 0x000918F4 File Offset: 0x0008FAF4
	// (set) Token: 0x06001666 RID: 5734 RVA: 0x000918EB File Offset: 0x0008FAEB
	public string SavePath { get; private set; }

	// Token: 0x17000385 RID: 901
	// (get) Token: 0x06001669 RID: 5737 RVA: 0x00091905 File Offset: 0x0008FB05
	// (set) Token: 0x06001668 RID: 5736 RVA: 0x000918FC File Offset: 0x0008FAFC
	public string ConfigPath { get; private set; }

	// Token: 0x17000386 RID: 902
	// (get) Token: 0x0600166B RID: 5739 RVA: 0x00091916 File Offset: 0x0008FB16
	// (set) Token: 0x0600166A RID: 5738 RVA: 0x0009190D File Offset: 0x0008FB0D
	public string CharacterPath { get; private set; }

	// Token: 0x0600166C RID: 5740 RVA: 0x00091920 File Offset: 0x0008FB20
	private void InitLists()
	{
		this.GiantessPaths = new List<string>();
		this.PlayerModelPaths = new List<string>();
		this.MaleNpcPaths = new List<string>();
		this.FemaleNpcPaths = new List<string>();
		this.ObjectPaths = new List<string>();
		this.SoundPaths = new List<string>();
		this.ScenePaths = new List<string>();
		this.LuaPaths = new List<string>();
	}

	// Token: 0x0600166D RID: 5741 RVA: 0x00091985 File Offset: 0x0008FB85
	private void LoadFromFile()
	{
		this.InitLists();
		this.ParseXmlFile();
	}

	// Token: 0x0600166E RID: 5742 RVA: 0x00091994 File Offset: 0x0008FB94
	private void ParseXmlFile()
	{
		foreach (string text in this.settingsPath)
		{
			if (File.Exists(text))
			{
				using (XmlReader xmlReader = XmlReader.Create(text))
				{
					while (xmlReader.Read())
					{
						if (xmlReader.NodeType == XmlNodeType.Element)
						{
							string name = xmlReader.Name;
							switch (name)
							{
							case "GiantessFolder":
								XmlResourceSettingReader.LoadAssetPath(xmlReader, this.GiantessPaths);
								break;
							case "FemaleNpcFolder":
								XmlResourceSettingReader.LoadAssetPath(xmlReader, this.FemaleNpcPaths);
								break;
							case "MaleNpcFolder":
								XmlResourceSettingReader.LoadAssetPath(xmlReader, this.MaleNpcPaths);
								break;
							case "ObjectFolder":
								XmlResourceSettingReader.LoadAssetPath(xmlReader, this.ObjectPaths);
								break;
							case "PlayerFolder":
								XmlResourceSettingReader.LoadAssetPath(xmlReader, this.PlayerModelPaths);
								break;
							case "SoundFolder":
								XmlResourceSettingReader.LoadAssetPath(xmlReader, this.SoundPaths);
								break;
							case "ScenesFolder":
								XmlResourceSettingReader.LoadAssetPath(xmlReader, this.ScenePaths);
								break;
							case "ScriptFolder":
								XmlResourceSettingReader.LoadAssetPath(xmlReader, this.LuaPaths);
								break;
							case "SavesFolder":
								this.SavePath = XmlResourceSettingReader.LoadAssetPath(xmlReader, this.SavePath);
								break;
							case "ScreenshotFolder":
								this.ScreenShotPath = XmlResourceSettingReader.LoadAssetPath(xmlReader, this.ScreenShotPath);
								break;
							case "ConfigFolder":
								this.ConfigPath = XmlResourceSettingReader.LoadAssetPath(xmlReader, this.ConfigPath);
								break;
							case "CharacterFolder":
								this.CharacterPath = XmlResourceSettingReader.LoadAssetPath(xmlReader, this.CharacterPath);
								break;
							}
						}
					}
				}
			}
		}
	}

	// Token: 0x0600166F RID: 5743 RVA: 0x00091C24 File Offset: 0x0008FE24
	private static void LoadAssetPath(XmlReader reader, ICollection<string> storageTarget)
	{
		string name = reader.Name;
		reader.Read();
		if (reader.HasValue)
		{
			if (Directory.Exists(reader.Value))
			{
				storageTarget.Add(reader.Value);
			}
			else
			{
				Debug.LogWarning(string.Concat(new string[]
				{
					"XML: Could not load entry '",
					name,
					"' path '",
					reader.Value,
					"'"
				}));
			}
		}
	}

	// Token: 0x06001670 RID: 5744 RVA: 0x00091CA0 File Offset: 0x0008FEA0
	private static string LoadAssetPath(XmlReader reader, string currentValue)
	{
		string name = reader.Name;
		reader.Read();
		if (reader.HasValue)
		{
			if (Directory.Exists(reader.Value))
			{
				if (currentValue != null)
				{
					Debug.LogWarning(string.Concat(new string[]
					{
						"XML: Entry '",
						name,
						"' was overwritten from '",
						currentValue,
						"' to '",
						reader.Value,
						"'"
					}));
				}
				return reader.Value;
			}
			Debug.LogWarning(string.Concat(new string[]
			{
				"XML: Could not load entry '",
				name,
				"' path '",
				reader.Value,
				"'"
			}));
		}
		return currentValue;
	}

	// Token: 0x04001915 RID: 6421
	private readonly string[] settingsPath = new string[]
	{
		string.Concat(new object[]
		{
			Application.dataPath,
			Path.DirectorySeparatorChar,
			"..",
			Path.DirectorySeparatorChar,
			"Settings.xml"
		}),
		Application.persistentDataPath + Path.DirectorySeparatorChar + "Settings.xml"
	};
}
